package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    @GetMapping("/albumInfo/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> findRankingList(@PathVariable Long category1Id,@PathVariable String dimension){
        List<AlbumInfoIndex> list = searchService.findRankingList(category1Id,dimension);
        return Result.ok(list);
    }
    /**
     *  更新所有分类下排行榜，由XXJob调用
     * @return
     */
    @GetMapping("/albumInfo/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }
    /**
     * 查询专辑 详情
     * @param albumId
     * @return
     */
    @GetMapping("/albumInfo/{albumId}")
    public Result<Map<String,Object>> getAlbumInfoDetail(@PathVariable Long albumId){
        Map<String,Object> map = searchService.getAlbumInfoDetail(albumId);
        return Result.ok(map);
    }

    /**
     * 搜索框自动补全
     * @param keyword
     * @return
     */
    @GetMapping("/albumInfo/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword){
        List<String> stringList = searchService.completeSuggest(keyword);
        return Result.ok(stringList);
    }

    /**
     *  上架专辑
     * @param albumId
     * @return
     */
    @GetMapping("/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId){
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    /**
     *  下架专辑
     * @param albumId
     * @return
     */
    @GetMapping("/albumInfo/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    /**
     *  专辑检索
     * @param albumIndexQuery
     * @return
     */
    @PostMapping("/albumInfo")
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    /**
     *  查/**
     * @param category1Id
     * @return
     */
    @GetMapping("/albumInfo/channel/{category1Id}")
    public Result<List<Map<String, Object>>> getTopCategory3HotAlbumList(@PathVariable Long category1Id){
        List<Map<String, Object>> map = searchService.getTopCategory3HotAlbumList(category1Id);
        return Result.ok(map);
    }


}




















